package com.itheima.a01threadpool;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class MyThreadPoolDemo1 {
    public static void main(String[] args) {
        //熟悉线程池的创建方式
        //1.创建线程池对象
//        ExecutorService pool1 = Executors.newCachedThreadPool();

        //创建可以指定线程数量的线程池
        ExecutorService pool2 = Executors.newFixedThreadPool(3);

        //提交任务
        pool2.submit(new MyRunnable());
        pool2.submit(new MyRunnable());
        pool2.submit(new MyRunnable());
        pool2.submit(new MyRunnable());
        pool2.submit(new MyRunnable());


        //关闭线程池,一般是不需要关闭线程池的,因为线程池的生命周期是和JVM的生命周期是一致的
        pool2.shutdown();
    }
}
